package com.slkj.shilixiaoyuanapp.ui.user.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.base.ActivityInfo;
import com.slkj.shilixiaoyuanapp.base.BaseActivity;
import com.slkj.shilixiaoyuanapp.data.UserRequest;
import com.slkj.shilixiaoyuanapp.net.HttpHeper;
import com.slkj.shilixiaoyuanapp.net.callback.CommonCallBack;
import com.slkj.shilixiaoyuanapp.view.CustomStateText;
import com.slkj.shilixiaoyuanapp.view.NumberEditText;
import com.slkj.shilixiaoyuanapp.view.dialog.LoadSuccessAndFailDialog;

import java.util.List;

import butterknife.BindView;
import butterknife.BindViews;
import butterknife.ButterKnife;
import butterknife.OnClick;


@ActivityInfo(layout = R.layout.yi_jian_fan_kui, title = "意见反馈")
public class YiJianFanKuiActivity extends BaseActivity {


    @BindViews({R.id.tv_type1, R.id.tv_type2, R.id.tv_type3, R.id.tv_type4})
    List<CustomStateText> typesView;
    int nowPos = -1;
    @BindView(R.id.edit_content)
    NumberEditText editContent;
    @BindView(R.id.edit_email)
    EditText editEmail;


    @Override
    protected void init() {

    }

    @OnClick(R.id.tv_sure)void up(){
        if (nowPos == -1){
            showToast("请选择反馈类型");
            return;
        }
        String body = editContent.getText().toString();
        if (TextUtils.isEmpty(body)){
            showToast("请输入反馈意见");
            return;
        }
        String email = editEmail.getText().toString();
        if (TextUtils.isEmpty(email)){
            showToast("请输入邮箱");
            return;
        }
        HttpHeper.get().userService()
                .addYjfk(body, UserRequest.getInstance().getUser().getTeacherSchoolId(),nowPos+1,email)
                .compose(getThread())
                .compose(bindToLifecycle())
                .subscribe(new CommonCallBack<String>(true,this) {
                    @Override
                    public void onCallBackSuccess(String data) {
                        LoadSuccessAndFailDialog.showSuccess(YiJianFanKuiActivity.this,data);
                        finish();
                    }
                });
    }

    @OnClick({R.id.tv_type1, R.id.tv_type2, R.id.tv_type3, R.id.tv_type4})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_type1:
                onTypeClick(0);
                break;
            case R.id.tv_type2:
                onTypeClick(1);
                break;
            case R.id.tv_type3:
                onTypeClick(2);
                break;
            case R.id.tv_type4:
                onTypeClick(3);
                break;
        }
    }

    void onTypeClick(int pos) {
        if (nowPos == pos) {
            return;
        }
        if (nowPos != -1)
            typesView.get(nowPos).setSelected(false);
        typesView.get(pos).setSelected(!typesView.get(pos).isSelected());
        nowPos = pos;
    }


}
